<?php
/**
 *
 * @category    API
 * @package     Api_Ajax
 * @author      trungpm
 */
class Api_Ajax
{
	private $template;

	/**
	 * Initial ajax progress template object
	 * @author	trungpm
	 */
	function __construct()
	{
		$this->template="<script type='text/javascript'>window.top.mk_update_progress(%s,'%s','%s');</script>";
	}

	/**
	 * Write into browser
	 * @author	trungpm
	 */
	private function write($a)
	{
		echo $a;
		ob_flush();
		flush();
	}

	/**
	 * Write into browser
	 * @author	trungpm
	 */
	function advance($perc,$msg1='',$msg2='')
	{
		$this->write(sprintf($this->template,$perc,$msg1,$msg2));
	}

	/**
	 * Detroy object
	 * @author	trungpm
	 */
	function __destruct()
	{
		$this->advance(-1);
		$this->write('</BODY></HTML>');
	}
}